package com.lonewalker.completablefuturedemo;

import java.util.concurrent.CompletableFuture;

/**
 * @author LoneWalker
 * @date 2023/2/12
 * @description
 */
public class demo8 {
    public static void main(String[] args) {
        CompletableFuture<Integer> completableFuture1 = CompletableFuture.supplyAsync(() -> {
            System.out.println("1号任务执行");
            return 5;
        });
        CompletableFuture<Integer> completableFuture2 = CompletableFuture.supplyAsync(() -> {
            System.out.println("2号任务执行");
            return 6;
        });
        CompletableFuture<Integer> completableFuture3 = CompletableFuture.supplyAsync(() -> {
            System.out.println("3号任务执行");
            return 7;
        });
        CompletableFuture<Integer> result = CompletableFuture.allOf(completableFuture1, completableFuture2, completableFuture3).thenApply(d -> {
            return completableFuture1.join() + completableFuture2.join() + completableFuture3.join();
        });
        System.out.println(result.join());
    }
}
